package com.small.act;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.small.R;
import com.small.commom.Action;
import com.small.commom.Common;

public class UserCentreActivity extends Activity {

	private Action action;
	private ImageButton btn_back, btn_logout;
	private LinearLayout btnUserInfo, btnChangeUser, btn_update, btnSysSetting;
	private RelativeLayout btnMyfav,btnfavShop,btnMsg;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_user_view);
		action = new  Action(UserCentreActivity.this);
		findView();
	}

	public void findView() {
		btnUserInfo = (LinearLayout) this.findViewById(R.id.btn_userinfo); 
		btnChangeUser = (LinearLayout) this.findViewById(R.id.btn_changeuser); 
		btn_update = (LinearLayout) this.findViewById(R.id.btn_update); 
		btnSysSetting = (LinearLayout) this.findViewById(R.id.btn_syssetting); 
		btnMyfav = (RelativeLayout) this.findViewById(R.id.btn_myfav); 
		btnfavShop = (RelativeLayout) this.findViewById(R.id.btn_favShop); 
		btnMsg  = (RelativeLayout) this.findViewById(R.id.btnMsg); 
		btn_back = (ImageButton) this.findViewById(R.id.btn_back);
		btn_logout = (ImageButton) this.findViewById(R.id.btn_logout);
		btn_logout.setVisibility(View.GONE);
		btn_back.setOnClickListener(onClick);
		btn_logout.setOnClickListener(onClick); 
		btnUserInfo.setOnClickListener(onClick); 
		btnChangeUser.setOnClickListener(onClick);  
		btn_update.setOnClickListener(onClick); 
		btnSysSetting.setOnClickListener(onClick);
		btnMyfav.setOnClickListener(onClick);  
		btnfavShop.setOnClickListener(onClick); 
		btnMsg.setOnClickListener(onClick);  
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		if (Common.model == null) {
			Intent i = new Intent(UserCentreActivity.this, LoginActivity.class);
			UserCentreActivity.this.startActivity(i);
			UserCentreActivity.this.finish();
		} else {
			btn_logout.setVisibility(View.VISIBLE);
			((TextView) this.findViewById(R.id.uset_txt_title)).setText(Common.model.getNickName());
		}
	}

	OnClickListener onClick = new OnClickListener() {

		@Override
		public void onClick(View v) {

			switch (v.getId()) {
			case R.id.btn_back://返回
				UserCentreActivity.this.finish();				
				break;
			case R.id.btn_logout://注销
				action.logOut();
				UserCentreActivity.this.finish();
				break;
			case R.id.btn_userinfo://个人信息
				action.getInstance().goToUserDetail();		
				break;
			case R.id.btn_changeuser://切换用户
				action.logOut();
				action.getInstance().goToLogin();
				break;
			case R.id.btn_update://版本升级
				action.showShortToast("功能暂未实现...");
				break;
			case R.id.btn_syssetting://系统设置
				action.getInstance().goToSysSetting();
				break;
			case R.id.btn_myfav://我的收藏
				 
				action.getInstance().goToMyFav();
				break;
			case R.id.btn_favShop://关注商家
				action.getInstance().goToMyFavShop();
				break;
			case R.id.btnMsg://消息盒子
				action.getInstance().goToAppMsg();
				break;

			}
		}
	};
}
